// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueQuillEditor from 'vue-quill-editor'

import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme

Vue.use(VueQuillEditor, /* { default global options } */)
//vue使用element ui
Vue.use(ElementUI)
//idea环境
axios.defaults.baseURL = "http://localhost:8888"
// axios.defaults.baseURL="http://192.168.50.72:8888"
//允许携带cookie
axios.defaults.withCredentials = true
//配置过后可以使用this.http方式使用axios
Vue.prototype.$http = axios
Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  if (to.path == "/login" || to.path == "/phone" || to.path == "/Register") {
    next();
  } else {
    if (localStorage.getItem("user")) {
      next();
    } else {
      alert("未登陆")
      next("/login")
    }
  }
})
//添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    if(response.data.code==403){
      localStorage.removeItem("user");
      router.push("/login")
    }
    else return response;
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
